package com.plian.system.controller.sys.user;

import com.plian.Tools.base.BaseController;
import com.plian.Tools.pagedata.PageData;
import com.plian.system.model.ObjResult;
import com.plian.system.model.R;
import com.plian.system.model.token.PassToken;
import com.plian.system.service.sys.orgzation.OrgzationService;
import com.plian.system.service.sys.per.UserOrgService;
import com.plian.system.service.sys.token.TokenService;
import com.plian.system.service.sys.user.ISysUserService;
import com.plian.system.service.sys.user.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "api/system")
public class SystemController extends BaseController {
    @Autowired
    UserService userService;

    @Autowired
    UserOrgService userOrgService;

    @Autowired
    OrgzationService orgzationService;

    @Autowired
    TokenService tokenService;

    @Autowired
    ISysUserService sysUserService;

    @PostMapping(value = "/login")
    @PassToken
    public ObjResult login(@RequestBody PageData pd) throws Exception {
        return userService.login(pd);
    }

    @GetMapping("/healthy")
    @PassToken
    public R healthy(){
        return R.success();
    }

    /**
     * 获取系统参数
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/getSystem")
    public ObjResult getSystem() throws Exception {
        return userService.getSystem();
    }
    /**
     * 获取系统参数
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/refreshToken")
    @PassToken
    public ObjResult refreshToken(@RequestBody PageData pd) throws Exception {
        return tokenService.refreshToken(pd);
    }

    @PostMapping(value="/getZhiyuanUrl")
    public ObjResult  getZhiTicket() throws Exception{
        return userService.getZhiyuanUrl();
    }

//    @GetMapping(value="/getBIUrl") //TODO DEL
//    public R<String> getBIUrl(){
//        return R.data(userService.getBIUrl());
//    }

    /**
     * 判断token是否合法
     * @param token
     * @return
     * @throws Exception
     */
    @GetMapping(value = "/checkToken")
    @PassToken
    public R checkToken(@RequestParam(value = "token",required = false) String token) throws Exception {
        return sysUserService.checkToken(token);
    }

}
